define([ "stjs", "superadmin/js/superadmin-module", "common/js/user-module",
		"ui.router", "common/js/util-module" ], function(stjs) {
	var app = angular.module('SuperadminApp',
			[ 'SuperadminModule', 'UserModule', "ui.router", "UtilModule" ]).config(
			function($stateProvider, $urlRouterProvider) {
				$urlRouterProvider.otherwise("/colegios");
				$stateProvider.state("colegios", {
					url : '/colegios',
					templateUrl : '/superadmin/colegios.html',
					controller : 'ColegiosCtrl'
				});

				$stateProvider.state("colegio", {
					templateUrl : '/superadmin/colegio.html',
					url : '/colegio/:idColegio',

				});
				$stateProvider.state("colegio.info", {
					templateUrl : '/superadmin/col-info.html',
					url : '/info',
					controller : 'ColInfoCtrl',
				});

				$stateProvider.state("colegio.usuarios", {
					url : '/usuarios',
					template : '<ui-view/>',
				// templateUrl : '/superadmin/col-usuarios.html',

				});

				_.forEach([ "coordinadores", "secretarios", "profesores" ], function(
						actor) {
					$stateProvider.state("colegio.usuarios." + actor, {
						url : '/' + actor,
						templateUrl : '/superadmin/col-usuarios.html',
						controller : 'ColUsuariosCtrl',
					});
				});
				$stateProvider.state("colegio.ofertaAcademica", {
					url : '/ofertaAcademica',
					template : '<ui-view/>'
				});
				$stateProvider.state("colegio.ofertaAcademica.materias", {
					url : '/materias',
					templateUrl : '/superadmin/col-materias.html',
					controller : 'ColMateriasCtrl'
				});
				$stateProvider.state("colegio.ofertaAcademica.grados", {
					url : '/grados',
					templateUrl : '/superadmin/col-grados.html',
					controller : 'ColGradosCtrl'
				});
				$stateProvider.state("colegio.ofertaAcademica.grado", {
					url : '/grado/:idGrado',
					templateUrl : '/superadmin/col-grado.html',
					controller : 'ColGradoCtrl'
				});
				$stateProvider.state("colegio.ofertaAcademica.materia", {
					url : '/materia/:idMateria',
					templateUrl : '/superadmin/col-materia.html',
					controller : 'ColMateriaCtrl'
				});

			});

	app.controller('SuperadminCtrl', function($scope, $window, User, $state) {
		$scope.user = User.getMyInfo();
		$scope.isState = function(state) {
			return $state.includes(state);
		}
		$scope.logOut = function() {
			User.logout({}, function() {
				$window.location.href = "/";
			}, function() {
				$window.location.href = "/";
			})
		};
	});

	@ClassDef:client.superadmin.ColegiosScope@
	app.controller('ColegiosCtrl', stjs.toAngularCtrl(ColegiosScope));
	
	@ClassDef:client.superadmin.ColInfoScope@
	app.controller('ColInfoCtrl', stjs.toAngularCtrl(ColInfoScope));

	@ClassDef:client.superadmin.ColUsuariosScope@
	app.controller('ColUsuariosCtrl',stjs.toAngularCtrl(ColUsuariosScope));

	@ClassDef:client.superadmin.ColMateriasScope@
	app.controller('ColMateriasCtrl',stjs.toAngularCtrl(ColMateriasScope));
	
	@ClassDef:client.superadmin.ColGradosScope@
	app.controller('ColGradosCtrl',stjs.toAngularCtrl(ColGradosScope));
	
	@ClassDef:client.superadmin.ColGradoScope@
	app.controller('ColGradoCtrl', stjs.toAngularCtrl(ColGradoScope));
	
	@ClassDef:client.superadmin.ColMateriaScope@
	app.controller('ColMateriaCtrl', stjs.toAngularCtrl(ColMateriaScope));
	
	return app;
});
